package leetcode;


/**
 * 删除排序数组中的重复项
 */
public class LeetCode26 {
    public int removeDuplicates(int[] nums) {
        if (nums.length <= 1) return nums.length;
        int i = 0, j = 0;
        while (j < nums.length) {
            if (nums[j] == nums[i]) {
                j++;
            } else {
                nums[++i] = nums[j++];
            }
        }
        return i + 1;
    }

    public static void main(String[] args) {
        LeetCode26 leetCode26 = new LeetCode26();
        System.out.println(leetCode26.removeDuplicates(new int[]{1, 1, 2}));
    }
}